package com.xhwl.logistics.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xhwl.common.enums.CodeEnum;
import com.xhwl.common.pojo.ResultJson;
import com.xhwl.common.pojo.cent.vehicle.VehcCarRecord;
import com.xhwl.common.query.cent.vehicle.CarRecordQuery;
import com.xhwl.logistics.converter.ToPage;
import com.xhwl.logistics.service.IVehcCarRecordService;
import com.xhwl.logistics.vo.VehicleAccessRecordVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lu.Aaron
 * @since 2021-03-05
 * @menu  车辆进出记录
 */
//@Controller
@RequestMapping("/carRecord")
@Api(tags = "车辆进出记录")
@Slf4j
public class VehcCarRecordController {
//    @Autowired   //IVehcCarRecordService的实现已被删除，由于之前删除含有easyexcel代码
    private IVehcCarRecordService vehcCarRecordService;

    @Autowired
    private ToPage toPage;

    //已被VehicleAccessRecordController相应的路径替代
    @ApiOperation(value = "车辆进出记录查询",notes = "输入框有required标识的字段为必填项", response = ResultJson.class, httpMethod = "POST")
    @ResponseBody
    @RequestMapping(value = "/page/test", method = RequestMethod.POST)
    public ResultJson carRecordPage(@RequestBody CarRecordQuery carRecordQuery) {
        Page<VehcCarRecord> vehcCarRecordPage =vehcCarRecordService.carRecordPage(carRecordQuery);

        Page<VehicleAccessRecordVO> page = toPage.toPageVehicleAccessRecordVO(vehcCarRecordPage);

        return  new ResultJson(true, CodeEnum.SUCCESS.getCode(),"查询成功",page);
    }

    @ApiOperation(value = "车辆进出记录导出",notes = "输入框有required标识的字段为必填项", response = ResultJson.class, httpMethod = "POST")
    @ResponseBody
    @RequestMapping(value = "/export", method = RequestMethod.POST)
    public void carRecordExport(@RequestBody CarRecordQuery carRecordQuery, HttpServletResponse response) {
        vehcCarRecordService.carRecordExport(carRecordQuery,response);
    }
}

